package com.unism.common.aop.sso;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.springframework.stereotype.Component;

import com.unism.common.aop.config.AopConfig;
import com.unism.common.aop.logger.Logor;
import com.unism.util.Config;
import com.unism.util.HttpSend;
import com.unism.util.ResponseByJson;

@Component("ssoLogoutResource")
@Path("/ssologout")
public class SsoLogoutResource {

	@GET
	@Path("/logout")
	@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
	@Logor(value = "用户登出")
	public Response logout(@Context HttpServletRequest request) {
		HttpSession session = request.getSession();
		ResponseByJson result = new ResponseByJson();
		if (session != null) {
			session.removeAttribute(AopConfig.userKey);
			session.invalidate();
		}
		HttpSend.getSendByToken(Config.getConfig("urlSsoLogout"), "",request.getHeader("Token"));
		result.setStatus(true);
		result.setMessage("用户登出成功");
		return Response.status(200).entity(result.toJsonString()).header("Access-Control-Allow-Headers", "X-extra-header")
				.allow("OPTIONS").build();
	}
}
